classes.sprites.Player = cc.PhysicsSprite.extend({
    move:false,
    direction:1,
    jumping:false,
    sprite:null,
    walking:false,
    hit:false,
    walkAnim:5,
    spriteFrameIndex:0,
    spriteFrameNamePrefix:"Stand_left",
    prevPrefix:"",
    jumpTimer:0,
    ctor:function (filename, body) {
        this._super();
        this.init();
        this.setBody(body);
        this.setScale(1.5);
        this.generateNewSprite(filename);
    },
    myUpdate:function (dt) {
        if(this.move) {
            this.walkAnim++;
            if(this.prevPrefix !== this.spriteFrameNamePrefix) {
                this.spriteFrameIndex = 0;
                this.generateNewSprite(this.spriteFrameNamePrefix + this.spriteFrameIndex + '.png');
            }
            if(this.walkAnim >= 8) {
                var i;
                this.spriteFrameIndex++;
                if ((this.spriteFrameIndex%4) === 0) {
                    i = 0;
                } else if ((this.spriteFrameIndex%4) === 1) {
                    i = 1;
                } else if ((this.spriteFrameIndex%4) === 2) {
                    i = 2;
                } else {
                    i = 1;
                }
                this.generateNewSprite(this.spriteFrameNamePrefix + i + '.png');
                this.walkAnim = 0;
            }
            this.prevPrefix = this.spriteFrameNamePrefix;
        }
        if(this.move) {
            this.setPosition(cc.p(this.getPosition().x+this.direction, this.getPosition().y));
        }
        if(this.hit) {
            app.getAudio().playEffect('res/audio/jump.ogg', false);
            this.getBody().applyImpulse(cp.v(0,1500), cp.v(0,0));
            this.jumping = true;
            this.hit = false;
        }
        if(this.jumping) {
            this.jumpTimer++;
            if(this.jumpTimer >= 60) {
                this.jumpTimer = 0;
                this.jumping = false;
            }
        }
    },
    jump: function() {
        if(this.jumping) return;
        this.jumping = true;
        this.getBody().applyImpulse(cp.v(0,1500), cp.v(0,0));
    },
    generateNewSprite: function(name) {
        this.removeChild(this.sprite);
        this.sprite = cc.Sprite.createWithSpriteFrameName(name);
        this.addChild(this.sprite);
    }
});